from __future__ import print_function
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import datetime

"""
   提供了__future__模块，让你在旧的版本中试验新版本的一些特性。例如2.7使用3的新特性
"""


def read_write():
    data = pd.read_csv('../data/sample/student.csv')
    print(data.head())

    data.to_pickle('../data/sample/student.pickle')

    data = pd.read_pickle('../data/sample/student.pickle')
    print(data.head())


def create_data():
    # 生成Series
    s = pd.Series([1, 3, 6, np.nan, 4, 1])
    print(s)

    # 生成以后的6天
    dates = pd.date_range('20160101', periods=6)

    # 生成6行4列的矩阵。indexs 为 s。列名为 columns
    df = pd.DataFrame(np.random.randn(6, 4), index=dates, columns=['A', 'B', 'C', 'D'])
    print(df['C'])


if __name__ == '__main__':
    array = np.array([x if x % 2 == 0 else None for x in range(12)])

    #  list 不能过滤其中的参数  ndarray 才可以使用这个数组过滤
    array = array[array != None]

    print(type(array), array)

    index = pd.Series(array)
    print(index)

    data = pd.DataFrame(np.random.normal(30, 10, size=len(array)), index=index, columns=['score'])
    print(data)

    data = pd.DataFrame({
        'B': 0.3,
        'c': [1, 2, 32, 5, 43],
        'date': datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')

    })
    print(data)

    print(data.index, data.columns, data.values, data.describe(), data.sort_values(by='c'))
